Skip to content

sqlite: add serialize() and deserialize() to DatabaseSync#62579

Merged
nodejs-github-bot merged 3 commits intonodejs:mainfrom
thisalihassan:sqlite-serialize-deserialize
Apr 10, 2026
Merged

sqlite: add serialize() and deserialize() to DatabaseSync#62579
nodejs-github-bot merged 3 commits intonodejs:mainfrom
thisalihassan:sqlite-serialize-deserialize

Conversation

@thisalihassan
Copy link
Copy Markdown
Contributor

@thisalihassan thisalihassan commented Apr 3, 2026

Add serialize() and .deserialize() methods to DatabaseSync, wrapping the sqlite3_serialize and sqlite3_deserialize. These allow extracting an in-memory database as a Uint8Array and loading one back enabling snapshots, cloning, etc..

Implemenation Notes:

serialize() wraps the SQLite allocated buffer directly in a V8 BackingStore to avoid copying the entire database. #ifdef V8_ENABLE_SANDBOX falls back to a copy path since that configuration forbids external backing stores. deserialize() must copy once because SQLite requires sqlite3_malloc64allocated memory.

Wrote test cases with Claude & GPT 5.4

Refs: #62575

@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/sqlite

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. sqlite Issues and PRs related to the SQLite subsystem. labels Apr 3, 2026
@thisalihassan thisalihassan force-pushed the sqlite-serialize-deserialize branch from 9b9212f to 52f29ac Compare April 3, 2026 22:28
}

unsigned char* buf =
static_cast<unsigned char*>(sqlite3_malloc64(byte_length));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this freed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sqlite3_deserialize() takes ownership of the buffer when passed SQLITE_DESERIALIZE_FREEONCLOSE

sqlite3_deserialize docs:
"If the SQLITE_DESERIALIZE_FREEONCLOSE bit is set in F, then SQLite will invoke sqlite3_free() on the serialization buffer when the database connection closes. If the SQLITE_DESERIALIZE_RESIZEABLE bit is set, then SQLite will try to increase the buffer size using sqlite3_realloc64() if writes on the database cause it to grow larger than M bytes."

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A comment to that effect would be helpful.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 3, 2026

Codecov Report

❌ Patch coverage is 75.30864% with 20 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.78%. Comparing base (f48ac91) to head (607d8c3).
⚠️ Report is 46 commits behind head on main.

Files with missing lines Patch % Lines
src/node_sqlite.cc 75.30% 11 Missing and 9 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #62579      +/-   ##
==========================================
+ Coverage   89.77%   89.78%   +0.01%     
==========================================
  Files         697      697              
  Lines      215749   215854     +105     
  Branches    41304    41319      +15     
==========================================
+ Hits       193681   193812     +131     
+ Misses      14161    14117      -44     
- Partials     7907     7925      +18     
Files with missing lines Coverage Δ
src/node_sqlite.h 80.64% <ø> (ø)
src/node_sqlite.cc 80.68% <75.30%> (-0.14%) ⬇️

... and 28 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

Add database.serialize() and database.deserialize() methods to
DatabaseSync, wrapping the sqlite3_serialize and sqlite3_deserialize
C APIs. These allow extracting an in-memory database as a Uint8Array
and loading one back, enabling snapshots, cloning, and transfer of
databases without filesystem I/O.

Refs: nodejs#62575
@thisalihassan thisalihassan force-pushed the sqlite-serialize-deserialize branch from f1cc0fe to 86127c0 Compare April 7, 2026 11:08
Signed-off-by: Ali Hassan <ali-hassan27@outlook.com>
@geeksilva97 geeksilva97 added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. labels Apr 8, 2026
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Apr 8, 2026
@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

@thisalihassan
Copy link
Copy Markdown
Contributor Author

@geeksilva97 it failed due to async-hooks.test-improper-order 😞

Can you please retrigger CI?

@geeksilva97 geeksilva97 added the request-ci Add this label to start a Jenkins CI on a PR. label Apr 9, 2026
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Apr 9, 2026
@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

@aduh95 aduh95 added the commit-queue Add this label to land a pull request using GitHub Actions. label Apr 10, 2026
@nodejs-github-bot nodejs-github-bot added commit-queue-failed An error occurred while landing this pull request using GitHub Actions. and removed commit-queue Add this label to land a pull request using GitHub Actions. labels Apr 10, 2026
@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

Commit Queue failed
- Loading data for nodejs/node/pull/62579
✔  Done loading data for nodejs/node/pull/62579
----------------------------------- PR info ------------------------------------
Title      sqlite: add serialize() and deserialize() to DatabaseSync (#62579)
   ⚠  Could not retrieve the email or name of the PR author's from user's GitHub profile!
Branch     thisalihassan:sqlite-serialize-deserialize -> nodejs:main
Labels     c++, author ready, needs-ci, sqlite
Commits    3
 - sqlite: add serialize() and deserialize()
 - add ownership comment to deserialize
 - doc: added mjs samples for sqlite
Committers 1
 - Ali Hassan <ali-hassan27@outlook.com>
PR-URL: https://github.com/nodejs/node/pull/62579
Refs: https://github.com/nodejs/node/issues/62575
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com>
------------------------------ Generated metadata ------------------------------
PR-URL: https://github.com/nodejs/node/pull/62579
Refs: https://github.com/nodejs/node/issues/62575
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com>
--------------------------------------------------------------------------------
   ℹ  This PR was created on Fri, 03 Apr 2026 22:24:19 GMT
   ✔  Approvals: 2
   ✔  - James M Snell (@jasnell) (TSC): https://github.com/nodejs/node/pull/62579#pullrequestreview-4075406936
   ✔  - Edy Silva (@geeksilva97): https://github.com/nodejs/node/pull/62579#pullrequestreview-4075976951
   ✔  Last GitHub CI successful
   ℹ  Last Full PR CI on 2026-04-10T12:26:18Z: https://ci.nodejs.org/job/node-test-pull-request/72602/
- Querying data for job/node-test-pull-request/72602/
✔  Build data downloaded
   ✔  Last Jenkins CI successful
--------------------------------------------------------------------------------
   ✔  No git cherry-pick in progress
   ✔  No git am in progress
   ✔  No git rebase in progress
--------------------------------------------------------------------------------
- Bringing origin/main up to date...
From https://github.com/nodejs/node
 * branch                  main       -> FETCH_HEAD
   4c4c9e7a47..9f0a3e636b  main       -> origin/main
✔  origin/main is now up-to-date
main is out of sync with origin/main. Mismatched commits:
 - bdc5e4d3c2 tools: improve backport review script
 - 9f0a3e636b tools: improve backport review script
--------------------------------------------------------------------------------
HEAD is now at 9f0a3e636b tools: improve backport review script
   ✔  Reset to origin/main
- Downloading patch for 62579
From https://github.com/nodejs/node
 * branch                  refs/pull/62579/merge -> FETCH_HEAD
✔  Fetched commits as 4dc18ef29d2a..607d8c37fb67
--------------------------------------------------------------------------------
[main fc1a691779] sqlite: add serialize() and deserialize()
 Author: Ali Hassan <ali-hassan27@outlook.com>
 Date: Sat Apr 4 03:16:53 2026 +0500
 4 files changed, 498 insertions(+)
 create mode 100644 test/parallel/test-sqlite-serialize.js
[main 4e332c261c] add ownership comment to deserialize
 Author: Ali Hassan <ali-hassan27@outlook.com>
 Date: Sat Apr 4 13:02:39 2026 +0500
 1 file changed, 3 insertions(+)
[main 5f16fa1eae] doc: added mjs samples for sqlite
 Author: Ali Hassan <ali-hassan27@outlook.com>
 Date: Wed Apr 8 18:48:07 2026 +0500
 1 file changed, 25 insertions(+)
   ✔  Patches applied
There are 3 commits in the PR. Attempting autorebase.
(node:800) [DEP0190] DeprecationWarning: Passing args to a child process with shell option true can lead to security vulnerabilities, as the arguments are not escaped, only concatenated.
(Use `node --trace-deprecation ...` to show where the warning was created)
Rebasing (2/6)
Executing: git node land --amend --yes
--------------------------------- New Message ----------------------------------
sqlite: add serialize() and deserialize()

Add database.serialize() and database.deserialize() methods to
DatabaseSync, wrapping the sqlite3_serialize and sqlite3_deserialize
C APIs. These allow extracting an in-memory database as a Uint8Array
and loading one back, enabling snapshots, cloning, and transfer of
databases without filesystem I/O.

Refs: #62575
PR-URL: #62579
Refs: #62575
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com>

[detached HEAD 233631a772] sqlite: add serialize() and deserialize()
Author: Ali Hassan <ali-hassan27@outlook.com>
Date: Sat Apr 4 03:16:53 2026 +0500
4 files changed, 498 insertions(+)
create mode 100644 test/parallel/test-sqlite-serialize.js
Rebasing (3/6)
Rebasing (4/6)
Executing: git node land --amend --yes
--------------------------------- New Message ----------------------------------
add ownership comment to deserialize

PR-URL: #62579
Refs: #62575
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com>

[detached HEAD 0ba8e44e24] add ownership comment to deserialize
Author: Ali Hassan <ali-hassan27@outlook.com>
Date: Sat Apr 4 13:02:39 2026 +0500
1 file changed, 3 insertions(+)
Rebasing (5/6)
Rebasing (6/6)
Executing: git node land --amend --yes
--------------------------------- New Message ----------------------------------
doc: added mjs samples for sqlite

Signed-off-by: Ali Hassan <ali-hassan27@outlook.com>
PR-URL: #62579
Refs: #62575
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com>

[detached HEAD 7cb570e470] doc: added mjs samples for sqlite
Author: Ali Hassan <ali-hassan27@outlook.com>
Date: Wed Apr 8 18:48:07 2026 +0500
1 file changed, 25 insertions(+)
Successfully rebased and updated refs/heads/main.

ℹ Add commit-queue-squash label to land the PR as one commit, or commit-queue-rebase to land as separate commits.

https://github.com/nodejs/node/actions/runs/24261613071

@aduh95 aduh95 added commit-queue Add this label to land a pull request using GitHub Actions. and removed commit-queue-failed An error occurred while landing this pull request using GitHub Actions. labels Apr 10, 2026
@aduh95 aduh95 added the commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. label Apr 10, 2026
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Apr 10, 2026
@nodejs-github-bot nodejs-github-bot merged commit 4a41a00 into nodejs:main Apr 10, 2026
87 checks passed
@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

Landed in 4a41a00

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs that have at least one approval, no pending requests for changes, and a CI started. c++ Issues and PRs that require attention from people who are familiar with C++. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. needs-ci PRs that need a full CI run. sqlite Issues and PRs related to the SQLite subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants